package com.amado.webservice;

import java.io.IOException;

import javax.xml.bind.JAXBException;

import com.amado.webservice.entity.Response;
import com.amado.webservice.util.XmlUtil;

public class TestXmlString {
	public static void main(String[] args) {
		testXmlToBean();
		testBeanToXml();
	}

	public static void testXmlToBean() {
		String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + "<response>\r\n" + "<code>0000</code>\r\n"
				+ "<msg>节点内容</msg>\r\n" + "</response>";
		try {
			Response response = XmlUtil.xmlToBean(xml, Response.class);
			System.out.println(response);
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void testBeanToXml() {
		Response response = new Response();
		response.setCode("001");
		response.setMsg("成功");
		String xmlString = null;
		try {
			xmlString = XmlUtil.beanToXml(response, Response.class);
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(xmlString);

	}
}
